package com.hxc.controller;

import com.hxc.anno.Log;
import com.hxc.entity.PageBean;
import com.hxc.entity.Result;
import com.hxc.entity.Student;
import com.hxc.entity.StudentQueryParam;
import com.hxc.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    /**
     * 分页查询学生信息
     * */
    @GetMapping
    public Result getStudentPage(StudentQueryParam param) {
        log.info("请求分页查询第学生信息：{}",param);
        PageBean page = studentService.getStudentPage(param);
        return Result.success(page);
    }
    /**
     * 根据Id查询学生信息
     * */
    @GetMapping("/{id}")
    public Result getStudentById(@PathVariable("id") Integer id) {
        log.info("开始查询id={}的学生信息",id);
        Student student = studentService.getStudentById(id);
        return Result.success(student);
    }
    /**
     * 新增学学员
     * */
    @Log
    @PostMapping
    public Result addStudent(@RequestBody Student student) {
        log.info("请求新增学员信息：{}",student);
        studentService.addStudent(student);
        return Result.success();
    }
    /**
     * 修改学员信息
     * */
    @Log
    @PutMapping
    public Result updateStudent(@RequestBody Student student) {
        log.info("请求修改学员信息：{}",student);
        studentService.updateStudent(student);
        return Result.success();
    }
    /**
     * 删除学员
     * */
    @Log
    @DeleteMapping("/{ids}")
    public Result deleteStudent(@PathVariable("ids") Integer[] ids) {
        log.info("请求删除学员：{}",ids);
        studentService.deleteStudent(ids);
        return Result.success();
    }
    /**
     * 违纪处理
     * */
    @Log
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable("id") Integer id, @PathVariable("score") Integer score) {
        log.info("请求给{}号学员记录违纪一次，扣除分数：{}",id,score);
        studentService.violation(id,score);
        return Result.success();
    }
}
